#ifndef EVIESYSTEMS_H_46d4b4e5_50a1_4b25_ae2e_a8712917eb01
#define EVIESYSTEMS_H_46d4b4e5_50a1_4b25_ae2e_a8712917eb01

/*
**
** Copyright (c) 2010 by Lorimark Solutions, LLC.
** All Rights Reserved.
** Send inquiries to: info@lorimarksolutions.com
**
*/

#include <avr/io.h>
#include <stdio.h>
#include <avr/interrupt.h>
#include <util/delay.h>
#include <avr/sfr_defs.h>

#define int8   signed   char
#define int16  signed   int
#define uint8  unsigned char
#define uint16 unsigned int
#define int32  signed   long
#define uint32 unsigned long
#define sint8  signed   char
#define sint16 signed   int
#define sint32 signed   long

/*
** Union of two data bytes.   Bytes can be accessed individually
**  or as signed two-byte integers.
**
*/
typedef union 
{
  uint16 u16;
  uint8  u8[2];
  sint16 s16;
  sint8  s8[2];
} db2_t;

/*
** Range. This structure contains two set points
**  called a 'range'.  It is used in calibration
**  settings.
**
*/
typedef struct
{
  db2_t lo;
  db2_t hi;
} range_t;

/*
** Scale.  This structure contains two ranges
**  used in scale conversions.  One range is
**  the input range, and the second is the
**  output range.
**
*/
typedef struct
{
  range_t i;
  range_t o;
} scale_t;

/*
**  Cell Voltage Monitor (eeprom)
**
**  This structure represents the devices that monitors
**   individual cells within the traction pack.
**
*/
typedef struct
{
  uint8 node;    // node id of this device ~ This is the logical
                 //  address this module occupies on the CAN bus.
                 //
  uint8 cells;   // cell count ~ Since this is a pack voltage monitor,
                 //  we need to know how many cells it's connected to
                 //
  uint8 tci;     // traction cell index ~ this is the physical base
                 //  of the entire traction pack cell address.  If the
                 //  vehicle has 32 cells, and each monitor connnects
                 //  to 8 cells per, and this was the third monitor,
                 //  then this cell index might be 24.
} mvc_t;


/*
** Traction Cell Voltage (ram)
**
** This structure holds the results of queries to 
**  the various modules to acquire the traction
**  voltage.  This structure is laid out in an 
**  array, and the TCM structures are mapped into
**  it by way of the .bar. variable.
**
*/
typedef struct
{
  uint8  status;
  uint16 raw;
  uint16 current;
  uint16 last;
  uint16 min;
  uint16 max;
} tcv_t;



#define ENABLE_INTERRUPTS sei()
#define DISABLE_INTERRUPTS cli()

#define forever for(;;)

#endif

